{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from add_ps_psd import AddPSPSD\n",
    "from QKDNetwork import QKDNetwork\n",
    "import numpy as np\n",
    "from concurrent.futures import ThreadPoolExecutor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def experiment(num_node, sd_num, mu):\n",
    "    # return [num_node, sd_num]\n",
    "    net = QKDNetwork(showTopology=False, num_node=num_node, sd_num=sd_num, alpha=0.35, hete=True)\n",
    "    a = AddPSPSD(net, mu)\n",
    "    su_indices, pvn_indices = a.ilp()\n",
    "    # print([len(su_indices), len(pvn_indices)])\n",
    "    return [len(su_indices), len(pvn_indices)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "node_num:  60 mu:  0.0\n",
      "32 167\n",
      "29 156\n",
      "26 136\n",
      "25 139\n",
      "27 176\n",
      "25 140\n",
      "27 168\n",
      "26 159\n",
      "26 164\n",
      "26 141\n",
      "27 145\n",
      "31 182\n",
      "28 175\n",
      "28 158\n",
      "24 139\n",
      "27 143\n",
      "28 161\n",
      "24 142\n",
      "26 131\n",
      "26 150\n",
      "26.9 153.6\n",
      "node_num:  60 mu:  0.2\n",
      "28 53\n",
      "24 43\n",
      "28 47\n",
      "29 50\n",
      "28 51\n",
      "30 60\n",
      "26 50\n",
      "28 45\n",
      "26 45\n",
      "30 50\n",
      "24 54\n",
      "28 52\n",
      "27 48\n",
      "29 56\n",
      "26 45\n",
      "30 53\n",
      "28 52\n",
      "27 50\n",
      "27 53\n",
      "22 50\n",
      "27.25 50.35\n",
      "node_num:  60 mu:  0.4\n",
      "30 52\n",
      "29 51\n",
      "27 48\n",
      "24 50\n",
      "28 45\n",
      "30 44\n",
      "27 42\n",
      "26 42\n",
      "27 44\n",
      "30 54\n",
      "29 51\n",
      "26 46\n",
      "28 45\n",
      "32 49\n",
      "30 50\n",
      "25 41\n",
      "30 46\n",
      "33 45\n",
      "25 47\n",
      "29 53\n",
      "28.25 47.25\n",
      "node_num:  60 mu:  0.6000000000000001\n",
      "36 52\n",
      "26 43\n",
      "29 51\n",
      "29 48\n",
      "29 47\n",
      "25 46\n",
      "29 47\n",
      "28 44\n",
      "29 43\n",
      "29 46\n",
      "30 43\n",
      "28 45\n",
      "29 43\n",
      "28 41\n",
      "25 42\n",
      "26 47\n",
      "31 47\n",
      "26 45\n",
      "29 43\n",
      "29 44\n",
      "28.5 45.35\n",
      "node_num:  60 mu:  0.8\n",
      "27 43\n",
      "30 49\n",
      "25 47\n",
      "27 45\n",
      "32 46\n",
      "29 45\n",
      "30 46\n",
      "28 48\n",
      "30 45\n",
      "25 43\n",
      "28 44\n",
      "27 43\n",
      "30 40\n",
      "26 46\n",
      "33 46\n",
      "32 47\n",
      "32 48\n",
      "30 44\n",
      "29 46\n",
      "27 47\n",
      "28.85 45.4\n"
     ]
    }
   ],
   "source": [
    "# for node_num in range(20, 60, 10):\n",
    "node_num = 60\n",
    "for mu in np.arange(0, 1.0, 0.2):\n",
    "    print(\"node_num: \", node_num, \"mu: \", mu)\n",
    "    tmp_arr_0 = []\n",
    "    tmp_arr_1 = []\n",
    "    with ThreadPoolExecutor(max_workers=20) as executor:\n",
    "        futures = [executor.submit(experiment, node_num, 30, mu) for _ in range(20)]\n",
    "        for future in futures:\n",
    "            ret = future.result()\n",
    "            tmp_arr_0.append(ret[0])\n",
    "            tmp_arr_1.append(ret[1])\n",
    "            print(ret[0], ret[1])\n",
    "    print(np.mean(tmp_arr_0), np.mean(tmp_arr_1))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "xs",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
